<?

if (empty($_SERVER['DOCUMENT_ROOT'])) {
	$_SERVER['DOCUMENT_ROOT'] = "/var/www/vhosts/geographs.org/httpdocs/";
}

include($_SERVER['DOCUMENT_ROOT'].'/includes/functions.inc.php');
include($_SERVER['DOCUMENT_ROOT'].'/portals/config.php');
include($_SERVER['DOCUMENT_ROOT'].'/groups/database.php');

if (false) {
	init_session();

	if (empty($_SESSION['user_id'])) {
		include($_SERVER['DOCUMENT_ROOT'].'/portals/login.inc.php');
		exit;
	}
}

$name = tempnam("/tmp",'dump');

$id = getOne("SELECT MAX(gridimage_id) FROM geograph_live.gridimage_search");

$url = "http://data.geograph.org.uk/get-search-data.php?auth={$CONF['download_auth']}&table=gridimage_search&id=$id&l=100";

print "$url\n\n";

passthru("GET '$url' > $name");

print "$name == ".filesize($name)."\n\n";

$cmd = "cat $name | mysql -h$db_host -u$db_user -p$db_passwd geograph_live";

                        list($usec, $sec) = explode(' ',microtime());
                        $querytime_before = ((float)$usec + (float)$sec);

passthru($cmd);

                        list($usec, $sec) = explode(' ',microtime());
                        $querytime_after = ((float)$usec + (float)$sec);

printf("Time = %.3f\n",$querytime_after-$querytime_before);


print "\n.\n";
